package List;

import java.util.ArrayList;
import java.util.Collections;

class Student implements Comparable<Student>{
    public String name;
    public String classes;
    public int grade;

    public Student(String name, String classes, int grade) {
        this.name = name;
        this.classes = classes;
        this.grade = grade;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", classes='" + classes + '\'' +
                ", grade=" + grade +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return this.grade-o.grade;
    }
}

public class Demo1 {

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(5);
        list.add(0);
        list.add(9);
        list.set(3,77);
        //Collections.sort(list);
        System.out.println(list);
    }

    public static void main1(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student("a","c1",100));
        students.add(new Student("b","c2",88));

        System.out.println(students);

        //对 自定义类型 进行排序，需要实现Comparable接口，重写 CompareTO()方法
        Collections.sort(students);
        System.out.println(students);

//        Iterator<Student> it=students.iterator();
//        while (it.hasNext()) {
//            System.out.println(it.next());
//        }

    }
}
